/**
 * Copyright 2017 Smart Society Services B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 */
package org.osgpfoundation.osgp.adapter.ws.da.presentation.ws;

import com.alliander.osgp.shared.exceptionhandling.ComponentType;
import com.alliander.osgp.shared.exceptionhandling.OsgpException;
import com.alliander.osgp.shared.exceptionhandling.TechnicalException;
import org.osgpfoundation.osgp.adapter.ws.da.application.mapping.DistributionAutomationMapper;
import org.osgpfoundation.osgp.adapter.ws.da.application.services.DistributionAutomationService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

public class GenericDistributionAutomationEndPoint {
    protected static final String NAMESPACE = "http://www.osgpfoundation.org/schemas/osgp/distributionautomation/defs/2017/04";

    @Autowired
    protected DistributionAutomationService service;

    @Autowired
    protected DistributionAutomationMapper mapper;

    protected void handleException(final Logger logger, final Exception e) throws OsgpException {
        // Rethrow exception if it already is a functional or technical
        // exception, otherwise throw new technical exception.
        logger.error("Exception occurred: ", e);
        if (e instanceof OsgpException) {
            throw (OsgpException) e;
        } else {
            throw new TechnicalException(ComponentType.WS_DISTRIBUTION_AUTOMATION, e);
        }
    }
}
